(function (global) {
    const setImmediate = global.setImmediate;
    global.InitComponent = function (root) {
        global.setImmediate = setImmediate;

        const params = new URLSearchParams(location.search);
        process.productName = params.get('n');
        const MainWindow = require(params.get('r'));
        const win = new MainWindow(JSON.parse(params.get('p')));
        win.win = window;
        document.defaultWindow = win;
        if (typeof win.id === 'string') window.__jelly_windows__.set(win.id, win);
        win.onCreated();
        win._render(root, document);
        win.onOpen();
    };

    window.minimize = () => {
        const {remote} = require('electron');
        remote.getCurrentWindow().minimize();
    };
    window.maximize = () => {
        const {remote} = require('electron');
        remote.getCurrentWindow().maximize();
    };
    window.unmaximize = () => {
        const {remote} = require('electron');
        remote.getCurrentWindow().unmaximize();
    };
    window.isFocused = () => {
        const {remote} = require('electron');
        remote.getCurrentWindow().isFocused();
    };

    global.__jelly_windows__ = new Map();
})(window || {});